<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleCreate">
          新增
        </a-button>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="firstUpperEntityName" setup>
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useJinhuiTable } from '/@/components/Jinhui/hooks/useJinhuiTable';
  import { getPage } from './tmDealerModify.api';
  import { columns, searchFormSchema } from './tmDealerModify.data';
  import { useModal } from '/@/components/Modal';
  const [registerModal, { openModal }] = useModal();
  const [registerTable, { reload, clearSelectedRowKeys }, { rowSelection }] = useJinhuiTable({
    title: '经销商-委改厂合作管理',
    api: getPage,
    columns,
    showActionColumn: false,
    formConfig: {
      schemas: searchFormSchema,
    },
    useSearchForm: true,
    fetchSetting: {
      pageField: 'page',
      // 传给后台的每页显示多少条的字段
      sizeField: 'rows',
      // 接口返回表格数据的字段
      listField: 'rows',
      // 接口返回表格总数的字段
      totalField: 'total',
    },
    beforeFetch: (params) => {
      return {
        'queryData.dealerName': params.dealerName,
        ...params,
      };
    },
  });

  function handleCreate() {
    openModal(true, {
      isUpdate: false,
    });
  }

  function refresh() {
    Promise.resolve(clearSelectedRowKeys()).then(() => {
      reload();
    });
  }
</script>
